package com.sdap2.controller;

import com.sdap2.common.constants.YsConstants;
import com.sdap2.common.model.ApiResult;
import com.sdap2.common.utils.WebClientUtil;
import com.sdap2.dto.YsTokenResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "监控管理")
@RestController
@RequestMapping("/api/monitor")
@RequiredArgsConstructor
public class MonitorController {

    private final WebClientUtil webClientUtil;

    @Operation(summary = "获取萤石云访问token")
    @GetMapping("/ys-token")
    public ApiResult<YsTokenResponse.YsTokenData> getYsToken() {
        String token = webClientUtil.getYsToken();
        
        // 构造返回数据
        YsTokenResponse.YsTokenData tokenData = new YsTokenResponse.YsTokenData();
        tokenData.setAccessToken(token);
        // 设置过期时间为7天后
        tokenData.setExpireTime(System.currentTimeMillis() + 6);
        
        return ApiResult.success(tokenData);
    }
} 